package com.xbongbong.saas.enums;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.xbongbong.i18n.util.I18nMessageUtil;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
 * 钉钉订单枚举
 *
 * @author bing
 */
public enum OrderTypeEnum {

	/**
	 * 新用户开通
	 */
	NEW_USER(0, "enum.orderType.name.new_user"),

	/**
	 * 30天内升级新签
	 */
	THIRTY_DAYS_WITHIN(1, "enum.orderType.name.thirty_days_within"),

	/**
	 * 30天外升级
	 */
	THIRTY_DAYS_OUTSIDE(2, "enum.orderType.name.thirty_days_outside"),

	/**
	 * 续签
	 */
	RENEWAL(3, "enum.orderType.name.renewal"),

	/**
	 * 续签升级
	 */
	RENEWAL_UPGRADE(4, "enum.orderType.name.renewal_upgrade"),
	;

	/** 枚举值 -- */
	private final int code;
	/** 枚举信息--中文名称 */
	private final String name;
	
	/**
	 * 构造一个<code>PushClassificationEnum</code>枚举对象
	 */
	OrderTypeEnum(int code, String name) {
		this.code = code;
		this.name = name;
	} 
	
	/**
	 * @return Returns the code.
	 */
	public int getCode() {
		return code;
	}
	
	/**
	 * @return Returns the name.
	 */
	public String getName() {
		return I18nMessageUtil.getMessage(name);
	}
	
	/**
     * 通过枚举<code>code</code>获得枚举
     *
     * @return OrderTypeEnum
     */
    public static OrderTypeEnum getByCode(Integer code) {
        for (OrderTypeEnum cacheCode : values()) {
            if (code.equals(cacheCode.getCode())) {
                return cacheCode;
            }
        }
        return null;
    }
	
	/**
	 * 获取全部枚举
	 * 
	 * @return List<WxErrorCodeEnum>
	 */
	public static List<OrderTypeEnum> getAllEnum() {
		List<OrderTypeEnum> list = new ArrayList<>();
        Collections.addAll(list, values());
		return list;
	}

    /**
     * 获取全部枚举
     * @return JSONArray
     */
	public static JSONArray getOrderTypeArray(){
		JSONArray array = new JSONArray();
		List<OrderTypeEnum> allEnum = getAllEnum();
		for(OrderTypeEnum orderTypeEnum : allEnum){
			Integer key = orderTypeEnum.getCode();
			String value = orderTypeEnum.getName();
			JSONObject jsonObject = new JSONObject();
			jsonObject.put("key", key);
			jsonObject.put("value", value);
			array.add(jsonObject);
		}
		return array;
	}
}
